home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C++
/
Frameworks
/
Sprocket Framework DR2
/
Sprocket Framework
/
SerialNumberProtection.cp
< prev
next >
Wrap
Text File
|
1996-06-15
|
6KB
|
292 lines
/*
File: SerialNumberProtection.cp
Project: Sprocket Framework 1.1 (DR2), released 6/15/96
Contains: Class which implements serial number-based protection (ie only X copies allowed
to being running at any one time)
To Do: ?
Sprocket Major Contributors:
----------------------------
Dave Falkenburg, producer of Sprocket 1.0
Bill Hayden, producer of Sprocket 1.1
Steve Sisak, producer of the upcoming Sprocket 2.0
Pete Alexander Steve Falkenburg Randy Thelen
Eric Berdahl Nitin Ganatra Chris K. Thomas
Marshall Clow Dave Hershey Leonard Rosenthal
Tim Craycroft Dave Mark Dean Yu
David denBoer Gary Powell
Cameron Esfahani Jon Summers Apple Computer, Inc.
Comments, Additions, or Corrections:
------------------------------------
Bill Hayden, Nikol Software <nikol@codewell.com>
*/
#include "SerialNumberProtection.h"
#include "SprocketMacros.h"
#include "UString.h"
// if set to zero, Sprocket does not bother to check for duplicate serial numbers over the network
// • Developer Note:
// -----------------
// While Network Security does work, it sometimes has strange, mostly harmless side-effects
// such as making the TE carat blink extremely fast. Use at your own risk and report bugs
// to me please at <nikol@codewell.com>.
#ifndef qNetworkSecurity
#define qNetworkSecurity 0
#endif
#if qNetworkSecurity
#include <Devices.h>
const Str32 kSS = "\pSprocketSecurity";
#endif
/*****************************************************************************/
TSerialNumberProtection::TSerialNumberProtection(short ResourceID)
{
fResourceID = ResourceID;
fNumOfLicenses = kNoLicense;
try
{
Handle temp;
temp = Get1Resource('STR#', ResourceID);
FailResErrorOrNil(temp);
ReleaseResource(temp);
FailResError();
}
catch(OSErr err)
{
throw err; // rethrow it to next level
}
}
/*****************************************************************************/
// This must be called AFTER either ReadRegistration() or WriteRegistration()
OSErr TSerialNumberProtection::EnableProtection(void)
{
#if qNetworkSecurity
OSErr err;
ATPParamBlock thePB;
short MPPDriverRef;
#define alert_Error 129
// open the .MPP driver
err = OpenDriver( "\p.MPP", &MPPDriverRef );
if ( noErr != err )
return err;
// open socket
SetMem( &thePB, 0, sizeof( thePB ) );
err = POpenATPSkt(&thePB, false);
if( noErr != err )
return err;
// register via nbp
err = RegisterName(thePB.ATP.atpSocket);
return err;
#else
return noErr;
#endif
}
/*****************************************************************************/
OSErr TSerialNumberProtection::RegisterName( UInt8 inSocket )
{
#if qNetworkSecurity
MPPParamBlock pb;
NBPSetNTE( (Ptr)&fNTE, (ConstStr32Param)&fSerialNumber, (ConstStr32Param)kSS, "\p*", inSocket );
pb.NBPinterval = 2;
pb.NBPcount = 3;
pb.NBPentityPtr = (Ptr)&fNTE;
pb.NBPverifyFlag = 1;
return( PRegisterName( &pb,false ) );
#else
#pragma unused (inSocket)
return noErr;
#endif
}
/*****************************************************************************/
TSerialNumberProtection::~TSerialNumberProtection()
{
#if qNetworkSecurity
MPPParamBlock pb;
pb.NBPentityPtr = (Ptr)&fNTE.nt.entityData;
PRemoveName(&pb, false);
#endif
}
/*****************************************************************************/
// overload this function to get the information from a different place
OSErr TSerialNumberProtection::ReadRegistration(StringPtr SN, StringPtr Name, StringPtr Company)
{
try
{
GetIndString(fSerialNumber, fResourceID, 1);
FailResError();
GetIndString(fName, fResourceID, 2);
FailResError();
GetIndString(fCompany, fResourceID, 3);
FailResError();
GetIndString(fPlainName, fResourceID, 4);
FailResError();
}
catch(OSErr err)
{
return err;
}
UnmangleRegistration();
pcpy(SN, fSerialNumber); // keep a safe copy
pcpy(Name, fName);
pcpy(Company, fCompany);
return noErr;
}
/*****************************************************************************/
// overload this function to put the information in a different place
OSErr TSerialNumberProtection::WriteRegistration(StringPtr SN, StringPtr Name, StringPtr Company)
{
OSErr err;
pcpy(fSerialNumber, SN); // keep a safe copy
pcpy(fName, Name);
pcpy(fCompany, Company);
pcpy(fPlainName, Name);
MangleRegistration();
err = SetIndString(fSerialNumber, fResourceID, 1);
if (noErr != err)
return err;
err = SetIndString(fName, fResourceID, 2);
if (noErr != err)
return err;
err = SetIndString(fCompany, fResourceID, 3);
if (noErr != err)
return err;
err = SetIndString(Name, fResourceID, 4);
return err;
}
/*****************************************************************************/
// overload this function to provide verification that the SN that was entered correctly
OSErr TSerialNumberProtection::VerifyRegistration(StringPtr /* SN */, StringPtr /* Name */, StringPtr /* Company */)
{
return noErr;
}
/*****************************************************************************/
// overload this function to provide your own enciphering mechanism
void TSerialNumberProtection::MangleRegistration(void)
{
for (short x = 1; x < fName[0]; x++)
{
fName[x] += (fCompany[(x % (fCompany[0] - 1)) + 1] % 9) - 5;
}
for (short x = 1; x < fCompany[0]; x++)
{
fCompany[x] += (fSerialNumber[(x % (fSerialNumber[0] - 1)) + 1] % 9) - 5;
}
for (short x = 1; x < fSerialNumber[0]; x++)
{
fSerialNumber[x] += (fPlainName[(x % (fPlainName[0] - 1)) + 1] % 9) - 5;
}
}
/*****************************************************************************/
// overload this function to provide your own deciphering mechanism
void TSerialNumberProtection::UnmangleRegistration(void)
{
for (short x = 1; x < fSerialNumber[0]; x++)
{
fSerialNumber[x] -= (fPlainName[(x % (fPlainName[0] - 1)) + 1] % 9) - 5;
}
for (short x = 1; x < fCompany[0]; x++)
{
fCompany[x] -= (fSerialNumber[(x % (fSerialNumber[0] - 1)) + 1] % 9) - 5;
}
for (short x = 1; x < fName[0]; x++)
{
fName[x] -= (fCompany[(x % (fCompany[0] - 1)) + 1] % 9) - 5;
}
}